<?php
/**
 * Created by PhpStorm.
 * User: kongqi
 * Date: 2019/10/4
 * Time: 13:16
 */

namespace App\Plugin\HostServer\Models;


class PnHostSvCategory extends HostServerBase
{
    public static function category($group_type = '',$where=[],$parent_id=0)
    {
        if ($group_type) {
            if (is_array($group_type)) {
                $data = self::whereIn('group_type', $group_type)->search($where)->where('is_checked',1)->sortDesc()->get()->toArray();
            } else {
                $data = self::where('group_type', $group_type)->search($where)->where('is_checked',1)->sortDesc()->get()->toArray();
            }
        } else {
            $data = self::get()->toArray();
        }


        $data = get_tree_option($data, $parent_id);
        return $data;
    }
    public function parents(){
        return $this->belongsTo(static::class,'parent_id','id');
    }
}